/*    This file is part of libepistle.
 *
 *    libepistle is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    libepistle is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with libepistle.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef EPISTLE_POLLING_H
#define EPISTLE_POLLING_H

#include <stdint.h>
#include <primo/err.h>

#define POLLING_FATAL -1
#define POLLING_OKAY 0
#define POLLING_END 1

typedef int (*Polling_react)(int epoll_fd, int fd, uint32_t events,
			     Err *err, void *extra);

enum {
	PM_ADD = 1,
	PM_REMOVE,
	PM_INPUT,
	PM_OUTPUT,
};

typedef int (*Pm_react)(int epoll_fd, int fd, int server_fd, int pm_event,
			Err *err, void *extra);
typedef int (*Server_check)(int fd, void *extra);

int
poll_add(int epoll_fd, int fd, Err *err);

int
poll_remove(int epoll_fd, int fd, Err *err);

int
poll_out(int epoll_fd, int fd, Err *err);

int
poll_out_off(int epoll_fd, int fd, Err *err);

int
polling(int *epoll_fd, Polling_react react, int fds[], Err *err, void *extra);

int
polling_mode(Pm_react react, int *epoll_fd, int fds[], Server_check s_check,
	     Err *err, void *extra);

#endif
